"""
给定01数组，每次选择相邻的3个位置翻转，问变成全1数组的最少操作次数
从首位置开始依次处理即可
"""
class Solution:
    def minOperations(self, nums: List[int]) -> int:
        n = len(nums)
        ans = 0
        for i in range(0, n - 2):
            if nums[i] == 0:
                nums[i] ^= 1
                nums[i + 1] ^= 1
                nums[i + 2] ^=1
                ans += 1
        return ans if nums[-2] == 1 and nums[-1] == 1 else -1